package com.mingchuang.administrator.mingchuang.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.mingchuang.administrator.mingchuang.utils.Constant;
import com.mingchuang.administrator.mingchuang.zip.FileUtils;
import com.mingchuang.administrator.mingchuang.zip.ZipUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * 文件接收完成后 处理整理数据
 */
public class ReceiveFileBroadcast extends BroadcastReceiver{
    private Context mContext;
    @Override
    public void onReceive(Context context, Intent intent) {

        //K27+983-1217.zip
        //玉环互通主线桥.zip
        //br.putExtra("path","玉环互通主线桥.zip");
        mContext = context;


        Toast.makeText(context,"ReceiveFileBroadcast :"+intent.getStringExtra("path"),Toast.LENGTH_SHORT).show();
        String path = intent.getStringExtra("path");


        //String fileName  = intent.getStringExtra("path");
        //文件解压
        UnzipTherd unzipTherd = new UnzipTherd(path);
        unzipTherd.start();









    }

   public class  UnzipTherd extends Thread{
       private String path;
       public UnzipTherd(String fileName){
           this.path = fileName;
       }

       @Override
       public void run() {
           String filePath = Constant.getReceivedPath() + File.separator +path;

           try {
               Log.d("kipeng",filePath);
               Log.d("kipeng" , Constant.getreUnzipPath());
               ZipUtil.unzip(filePath, Constant.getreUnzipPath()+File.separator + "玉环互通主线桥");
           } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }
           FileUtils.read(mContext, Constant.getreUnzipPath()+File.separator + "玉环互通主线桥");

           ///storage/sdcard0/MC/received/玉环互通主线桥


          /* try {
               ZipUtil.zip("", "", Constant.getReceivedPath()+File.separator+"玉环互通主线桥");
           } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }*/

       }
   }
}
